﻿
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<style type="text/css">
    .form .formValue input.form-control {
        height: 32px;
        line-height: 32px;
        padding: 0px;
        resize: none;
        border-radius: 0px;
        box-shadow: none;
        text-indent: 5px
    }

    .textValue {
        width: 100%;
    }

    .selectbox {
        color: #444;
        line-height: 34px;
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        height: 34px;
        width: 100%;
    }

    .search {
        margin-left: 10px;
        padding: 0px;
    }

    table td {
        height: 40px;
        line-height: 40px;
    }

    .zdyPanel {
        background-color: #fff;
        border-top: 1px solid #ddd;
        border-left: 1px solid #ddd;
        border-right: 1px solid #ddd;
        margin: 0px;
        float: left;
        width: 100%;
    }

    .zdyTool {
        float: left;
        padding-left: 10px;
        width: 100%;
    }

    .zdyBar {
        padding: 0px;
        margin: 0px;
        margin-top: 3px;
    }

    .zdyUL {
        list-style-type: none;
        margin: 5px 0px 0px -3px;
        padding: 0px;
    }

        .zdyUL li {
            float: left;
            list-style: none;
            height: 24px;
            line-height: 22px;
        }

            .zdyUL li a {
                cursor: pointer;
                padding: 5px 10px;
                border-radius: 4px;
            }

            .zdyUL li i {
                margin-right: 4px;
                font-size: 13px;
                color: #666;
                vertical-align: middle;
                margin-top: -1px;
            }

            .zdyUL li a:hover {
                text-decoration: none;
                background-color: #1ABC9C;
                color: #fff;
            }

    .zdyGirdPanel {
        width: 100%;
        margin: 0px;
        padding: 0px;
        float: left;
    }

    .zdyContentPanel {
        width: 100%;
        margin: 5px 0px 0px 0px;
        padding: 0px;
        float: left;
    }

    .zdyFont {
        padding-left: 5px;
        color: #ff6a00;
    }

    .autocomplete-suggestions {
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
        border: 1px solid #999;
        background: #FFF;
        cursor: default;
        overflow: auto;
        -webkit-box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64);
        -moz-box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64);
        box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64);
    }

    .autocomplete-selected {
        background: #F0F0F0;
    }

    .autocomplete-suggestion {
        padding: 2px 5px;
        white-space: nowrap;
        overflow: hidden;
    }

    .autocomplete-no-suggestion {
        padding: 2px 5px;
    }

    .zdyUL {
        list-style-type: none;
        margin: 5px 0px 0px -3px;
        padding: 0px;
    }

        .zdyUL li {
            float: left;
            list-style: none;
            height: 24px;
            line-height: 22px;
        }

            .zdyUL li a {
                cursor: pointer;
                padding: 5px 10px;
                border-radius: 4px;
            }

            .zdyUL li i {
                margin-right: 4px;
                font-size: 13px;
                color: #666;
                vertical-align: middle;
                margin-top: -1px;
            }

            .zdyUL li a:hover {
                text-decoration: none;
                background-color: #1ABC9C;
                color: #fff;
            }

    .zdyGirdPanel {
        padding-top: 3px;
    }

    .form .formValue {
        padding: 1px 3px;
    }
</style>
<script>
    var resultData = {};
    $(function () {
        $("#state_horizon a.btn-default").click(function () {
            $("#state_horizon a.btn-default").removeClass("active");
            $(this).addClass("active");
            $('#btn_search').trigger("click");
        });
        GetItems();
        gridList();
    });

    function GetItems() {
        resultData = getCache("DEMAND_MYDEMAND");
        if (!resultData || resultData.length <= 0) {
            $.ajax({
                url: "/ClientManager/DemandInfos/GetItems",
                dataType: "json",
                async: false,
                success: function (data) {
                    resultData = data;
                    InitControl();
                    setCache("DEMAND_MYDEMAND", data);
                }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                }
            });
        } else {
            InitControl();
        }
    }

    function InitControl() {
        //var F_CityId = resultData.F_ActivityCityId;
        //for (var i = 0; i < F_CityId.length; i++) {
        //    $("#F_CityId").append("<option value='" + F_CityId[i].F_ItemCode + "'>" + F_CityId[i].F_ItemName + "</option>");
        //}
        $("#F_CityId").bindSelect({
            url: "/ClientManager/ClientInfos/GetAllCitys",
            search: true,
            id: "F_EnCode",
            text: "F_FullName"
        });

        var F_ActivityType = resultData.F_ActivityType;
        for (var i = 0; i < F_ActivityType.length; i++) {
            $("#F_ActivityType").append("<option value='" + F_ActivityType[i].F_ItemCode + "'>" + F_ActivityType[i].F_ItemName + "</option>");
        }

        var Clients = [];
        var SiteClients = resultData.SiteClients;
        for (var i = 0; i < SiteClients.length; i++) {
            Clients.push({ value: SiteClients[i].F_ClientName, data: SiteClients[i].F_Id });
        }

        $("#F_ClientName").autocomplete({
            lookup: Clients,
            onSelect: function (suggestion) {
                $("#hd_ClientName").val(suggestion.data);
            }
        });
    }

    function gridList() {
        var $gridList = $("#gridList");
        var queryJson = {};
        $gridList.dataGrid({
            url: "/ClientManager/DemandInfos/GetGridDataByUserId",
            postData: { queryJson: JSON.stringify(queryJson) },
            height: 630,
            colModel: [
                {
                    label: '需求单状态', name: 'F_State', width: 80, formatter: function (cellvalue) {
                        if (cellvalue == "0") {
                            return '需求单';
                        }
                        else if (cellvalue == "1") {
                            return '有效需求单';
                        }
                        else if (cellvalue == "2") {
                            return '无效需求';
                        }
                    }
                },
                {
                    label: '需求进度', name: 'F_OrderState', width: 80, formatter: function (cellvalue) {
                        if (cellvalue == "-1") {
                            return '<span style=\'color:red;\'></span>';
                        }
                        else if (cellvalue == "0") {
                            return '<span style=\'color:#FC8675;\'>待指派</span>';
                        }
                        else if (cellvalue == "1") {
                            return '<span style=\'color:#1ABC9C;\'>场地推荐</span>';
                        }
                        else if (cellvalue == "2") {
                            return '<span style=\'color:#1ABC9C;\'>带看场地</span>';
                        }
                        else if (cellvalue == "3") {
                            return '<span style=\'color:#1ABC9C;\'>意向场地</span>';
                        }
                        else if (cellvalue == "4") {
                            return '<span style=\'color:#1ABC9C;\'>价格协商</span>';
                        }
                        else if (cellvalue == "5") {
                            return '<span style=\'color:#1ABC9C;\'>场地预定</span>';
                        }
                        else if (cellvalue == "6") {
                            return '<span style=\'color:#1ABC9C;\'>用印申请</span>';
                        }
                        else if (cellvalue == "7") {
                            return '<span style=\'color:#1ABC9C;\'>合同审核</span>';
                        } else if (cellvalue == "8") {
                            return '<span style=\'color:#1ABC9C;\'>订单完成</span>';
                        }
                    }
                },
                {
                    label: '需求来源', name: 'F_Source', align: 'left', width: 80, formatter: function (cellvalue) {
                        if (cellvalue == "0") {
                            return '400电话';
                        } else if (cellvalue == "1"){
                            return '销售自拓';
                        } else if (cellvalue == "2") {
                            return '网站订单';
                        } else if (cellvalue == "3") {
                            return '小程序订单';
                        } else if (cellvalue == "4") {
                            return 'App订单';
                        }
                    }
                },
                { label: '公司名称', name: 'F_ClientName', width: 80, align: 'left' },
                {
                    label: '品牌名称', name: 'F_BrandName', width: 80, align: 'left'
                },
                {
                    label: '项目组', name: 'F_ProjectName', width: 80, align: 'left'
                },
                {
                    label: '活动主题', name: 'F_ActivityTheme', width: 120, align: 'left'
                },
                {
                    label: '活动类型', name: 'F_ActivityType', width: 80, align: 'left', formatter: function (cellvalue) {
                        return GetDictionaries(cellvalue,"F_ActivityType");
                    }
                },
                { label: '预算金额(元)', name: 'F_DemandCash', width: 80, align: 'left' },
                { label: '活动开始日期', name: 'F_ActivityStartDate', width: 80, align: 'left' },
                {
                    label: '活动结束日期', name: 'F_ActivityEndDate', width: 80, align: 'left'
                },
                {
                    label: '活动城市', name: 'F_ActivityCityId', align: 'left', width: 80, formatter: function (cellvalue) {
                        return GetDictionaries(cellvalue, "F_ActivityCityId");
                    }
                },
                {
                    label: '场地类型', name: 'F_SiteType', width: 80, align: 'left', formatter: function (cellvalue) {
                        return GetDictionaries(cellvalue, "F_SiteType");
                    }
                },
                { label: '活动人数', name: 'F_PersionNumber', width: 80, align: 'left' },
                { label: '空间面积(㎡)', name: 'F_SiteArea', width: 80, align: 'left' },
                { label: '层高(m)', name: 'F_Height', width: 80, align: 'left' },                
                { label: '销售人员', name: 'F_RealName', width: 80 },
                { label: '需求创建时间', name: 'F_CreatorTime', width: 130 },
                { label: '', name: 'F_Id', hidden: true },
                { label: '', name: 'contactId', hidden: true },
                { label: '', name: 'F_ClientId', hidden: true },
                { label: '', name: 'F_ProjectId', hidden: true },
                { label: '', name: 'F_BrandId', hidden: true },
                { label: '', name: 'F_OrderId', hidden: true },
                { label: '', name: 'F_OrderState', hidden: true }
            ],
            pager: "#gridPager",
            viewrecords: true,
            multiselect: false,
            sortname: 'F_Id',
            ondblClickRow: function (rowid, iRow, iCol, e) {
                var rowobj = $("#gridList").jqGridRowValue();
                btn_Update();
            },
            loadComplete: function (data) {

            }
        });
    }

    function Detail() {
        var rowobj = $("#gridList").jqGridRowValue();
        if (rowobj.F_Id) {
            $.modalOpen({
                id: "editForm",
                title: "详细需求",
                url: "/ClientManager/DemandInfos/Details?F_Id=" + rowobj.F_Id + "&contactId=" + rowobj.contactId + "&F_ClientId=" + rowobj.F_ClientId +"",
                width: "1200px",
                height: "850px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                },
                btn: null
            });
        } else {
            $.modalAlert("请选中行数据！", "warning");
        }
    }

    function GetDictionaries(value, type) {
        if (type == "F_SiteType") {
            var strHtml = "";
            for (var i = 0; i < resultData.F_SiteType.length; i++) {
                if (value == resultData.F_SiteType[i].F_ItemCode) {
                    return resultData.F_SiteType[i].F_ItemName;
                }
            }
            return '';
        } else if (type == "F_ActivityCityId") {
            var strHtml = "";
            for (var i = 0; i < resultData.F_ActivityCityId.length; i++) {
                for (var j = 0; j < value.split(',').length; j++) {
                    if (j == value.split(',').length - 1) {
                        if (value.split(',')[j] == resultData.F_ActivityCityId[i].F_EnCode) {
                            strHtml += resultData.F_ActivityCityId[i].F_FullName;
                        }
                    } else {
                        if (value.split(',')[j] == resultData.F_ActivityCityId[i].F_EnCode) {
                            strHtml += resultData.F_ActivityCityId[i].F_FullName + ",";
                        }
                    }
                }
            }
            return strHtml;
        } else if (type == "F_ActivityType") {
            for (var i = 0; i < resultData.F_ActivityType.length; i++) {
                if (value == resultData.F_ActivityType[i].F_ItemCode) {
                    return resultData.F_ActivityType[i].F_ItemName;
                }
            }
            return '';
        }
    }

    function btn_onSearch() {
        var $gridList = $("#gridList");
        var queryJson = {
            F_DemandCash: $("#F_DemandCash").val(),
            F_ActivityCityId: $("#F_CityId").val(),
            F_ActivityType: $("#F_ActivityType").val(),
            F_ClientName: $("#F_ClientName").val(),
            F_ActivityStartDate: $("#F_ActivityStartDate").val(),
            F_CreatorTime: $("#F_CreatorDate").val(),
            F_State: $("#state_horizon a.active").attr('data-value')
        };
        $gridList.jqGrid('setGridParam', {
            postData: { queryJson: JSON.stringify(queryJson) },
        }).trigger('reloadGrid');
    }

    function btn_Add() {
        $.modalOpen({
            id: "addForm",
            title: "新建需求",
            url: "/ClientManager/DemandInfos/Form?F_Id=&contactId=",
            width: "1200px",
            height: "950px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }

    function btn_Update() {
        var rowobj = $("#gridList").jqGridRowValue();
        if (rowobj.F_Id) {
            $.modalOpen({
                id: "editForm",
                title: "编辑需求",
                url: "/ClientManager/DemandInfos/Form?F_Id=" + rowobj.F_Id + "&contactId=" + rowobj.contactId + "&F_ClientId=" + rowobj.F_ClientId + "&F_ProjectId=" + rowobj.F_ProjectId + "&F_BrandId=" + rowobj.F_BrandId + "&F_OrderId=" + rowobj.F_OrderId + "",
                width: "1200px",
                height: "800px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        } else {
            $.modalAlert("请选中行数据！", "warning");
        }
    }
</script>
<div class="zdyPanel">
    <div class="zdyBar" style="float:left;white-space:nowrap;width:50%;">
        <div class="search">
            <table class="form" style="width:100%;">
                <tr>
                    <td class="formValue">
                        <select id="F_CityId" name="F_CityId" class="selectbox">
                            <option value="">==请选择城市==</option>
                        </select>
                    </td>
                    <td class="formValue">
                        <select id="F_ActivityType" name="F_ActivityType" class="selectbox">
                            <option value="">==请选择活动类型==</option>
                        </select>
                    </td>
                    <td class="formValue">
                        <div class="input-group" style="width:100%;">
                            <input type="text" id="F_DemandCash" class="form-control textValue" placeholder="请输入预算金额,结果大于预算金额" />
                            <span class="input-group-addon"><i class="glyphicon glyphicon-usd"></i></span>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="formValue">
                        <div class="input-group" style="width:100%;">
                            <input type="text" id="F_ClientName" class="form-control textValue" placeholder="请输入公司名称" />
                            <span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span>
                        </div>
                    </td>
                    <td class="formValue">
                        <input type="text" id="F_ActivityStartDate" class="form-control input-wdatepicker" onfocus="WdatePicker()" placeholder="请输入活动开始时间" />
                    </td>
                    <td class="formValue">
                        <input type="text" id="F_CreatorDate" class="form-control input-wdatepicker" onfocus="WdatePicker()" placeholder="请输入需求创建时间" />
                    </td>
                </tr>
                <tr>
                    <td class="formValue" colspan="2">
                        <div id="state_horizon" class="btn-group">
                            <a class="btn btn-default active" data-value="-1">全部</a>
                            <a class="btn btn-default" data-value="0">需求单</a>
                            <a class="btn btn-default" data-value="1">有效需求单</a> 
                            <a class="btn btn-default" data-value="2">无效需求单</a>  
                        </div>
                    </td> 
                    <td class="formValue">
                        <a class="btn btn-primary" onclick="btn_onSearch()" id="btn_search">按条件搜索</a>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <div class="zdyBar" style="float:right;white-space:nowrap;width:50%;padding-top:5px;">
        <div style="float:right;">
            <div class="btn-group">
                <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
            </div>
            @*<div class="btn-group">
                <a class="btn btn-primary" onclick="btn_Add()"><i class="fa fa-eraser">新建需求</i></a>
            </div>*@
            @*<div class="btn-group">
                <a class="btn btn-primary" onclick="btn_Update()"><i class="fa fa-pencil-square-o">编辑需求</i></a>
            </div>*@
        </div>        
    </div>
</div>
<div class="zdyGirdPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>
